package cn.shopifymall.externaltaskjavaboot.config;

import org.camunda.bpm.client.spring.annotation.ExternalTaskSubscription;
import org.camunda.bpm.client.task.ExternalTaskHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author 孤风雪影
 * @Email gitee.com/efairy520
 * @Date 2024/5/11 22:07
 * @Version 1.0
 */
@Configuration
public class SelfRepairService {

    @Bean
    @ExternalTaskSubscription(topicName = "try_self_repair", processDefinitionKeyIn = {"Process_external_task"}, lockDuration = 50000)
    public ExternalTaskHandler doSelfRepair() {
        return (externalTask, externalTaskService) -> {
            boolean isFree = externalTask.getVariable("isFree");
            if (isFree) {
                //设置1，每隔5秒重试一次
                externalTaskService.handleFailure(externalTask, "免费维修", "打印异常堆栈", 1, 5000);
            } else {
                externalTaskService.complete(externalTask);
            }
        };
    }

}
